<template>
	<view class="body">
		<view class="item">
			<view class="title" style="display: flex;">
				产品名称<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入产品名称" border="none" v-model="form.name" />
			</view>
		</view>
		<view class="item1">
			<view class="title" style="display: flex;">
				产品描述<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys1">
				<textarea style="border: 0px;" placeholder="请输入产品描述" border="none" v-model="form.description" />
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				起拍价格<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入起拍价格" border="none" v-model="form.startPrice" />
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				库存<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入库存" border="none" v-model="form.count" />
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				类型<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				 <view>
					
				    <uni-data-select
				      v-model="form.typeId"
				      :localdata="range"
				      @change="change"
				    ></uni-data-select>
				  </view>
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				拍卖方式<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				 <view>
					
				    <uni-data-select
				      v-model="form.sellType"
				      :localdata="sellType"
				      @change="changetype"
				    ></uni-data-select>
				  </view>
			</view>
		</view>
		<view class="">
			<uni-file-picker limit="1" title="请上传图片" @select="select" @progress="progress"
				@success="success"></uni-file-picker>
		</view>

		<view class="bottom">
			<view class="button" @click="submit">提交</view>
			<view class="button" @click="back">返回</view>
		</view>
	</view>
</template>

<script>
	import apis from '@/api/index.js'
	import {
		requestApi,uphttp
	} from '@/utils/request.js'
	// 导入公共组件方法
	import common from '@/common/js/common.js';
	export default {
		mixins: [common],
		data() {
			return {
				userInfo: {},
				form:{
					count:1,
				},
				productstype:{},
				products:{},
				range:[],
				sellType:[
					{value:0,text:"普通拍卖"},
					{value:1,text:"荷式拍卖"},
				]
			}
		},
		onLoad(e) {
			if(e.status==1){
				this.products.productId = e.id;
				this.getInfo();
			}
			this.userInfo = uni.getStorageSync("user");
			this.form.ownerId = this.userInfo.userId;
			this.getList();
		},
		methods: {
			getInfo(){
				requestApi(apis.products.productDetail,this.products,'post').then(res=>{
					this.form =res.data;
				})
			},
			getList(){
				requestApi(apis.productstype.list,this.productstype,"get").then(res=>{
					this.range = res.data;
					this.range.forEach(item=>{
						item.text = item.typeName;
						item.value = item.typeId;
					})
				})
			},
			change(e){
			console.log(e)	
			},
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
				const url = e.tempFilePaths[0];
				uni.uploadFile({
					url: G.UPload,
					filePath: url,
					name: 'file',
					header: {
						'token':'Bearer ' + uni.getStorageSync("token"),
					},
					success: (res) => {
						console.log(res);
						if (res.statusCode == 200) {
						var result = JSON.parse(res.data)
						this.form.image = "/"+result.data.fileName
						
						console.log("result",result)
						console.log("this.userInfo.icon",this.userInfo.icon)
						
						}
					}
				});
			},
			// 获取上传进度
			progress(e) {
				console.log('上传进度：', e)
			},

			// 上传成功
			success(e) {
				console.log(e)
			},
			back(){
			uni.navigateBack({
				delta:1
			})	
			},
			viado(){
				if(
				this.form.name!=null&&this.form.name!=''
				&&this.form.description!=null&&this.form.description !=''
				&&this.form.startPrice!=null&&this.form.startPrice !=''
				){
					return true;
				}else{
					return false;
				}
			},
			submit(){
				console.log(this.form);
				this.form.currentPrice = this.form.startPrice;
				if(this.viado()){
					requestApi(apis.products.save,this.form,'POST').then(res=>{
						if(res.code==200){
							uni.showToast({
								icon:"success",
								title:"添加成功"
							})
						}
					})
				}else{
					this.form = {};
					this.form.ownerId =this.userInfo.userId;
					uni.showToast({
						icon:"error",
						title:"数据为空"
					})
				}
				
					
			}
		}
	}
</script>

<style>
	.body {
		padding: 0 32rpx;
		min-height: 100vh;
		background-color: #fff;
	}

	.example-body {
		padding: 10px;
		padding-top: 0;
	}

	.img {
		width: 150rpx;
		height: 150rpx;
	}

	.item {
		display: flex;
		padding: 24rpx 0px;
		align-items: center;
		position: relative;
		/* justify-content: space-between; */
		border-bottom: 1px solid #fafafa;
	}
	.item1{
	
		padding: 24rpx 0px;
		align-items: center;
		position: relative;
		/* justify-content: space-between; */
		border-bottom: 1px solid #fafafa;
	}

	.block {
		width: 100%;
		height: auto;
		border-bottom: 24rpx solid #F1F6FB;
		padding: 0 32rpx 32rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}

	.title {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
	}

	.title1 {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
		justify-content: space-between;
		position: absolute;
		top: -20rpx;
	}

	.in-ys {
		width: 80%;
		border-radius: 8rpx;
		background: #F6F6F6;
	}
	.in-ys1 {
		width: 100%;
		border-radius: 8rpx;
		background: #F6F6F6;
	}
	.button{
		
		width: 40%;
		
		color: #fff;
		background-color: #07b1ff;
		padding: 32rpx;
		border-radius: 64rpx;
		text-align: center;
	}
	.bottom{
		position: absolute;
		bottom: 40rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
</style>
